import hashlib
chunk_cnt=0
dic=dict()
w=1024

d=100

r=50
#file_path=input("请输入文件的路径")

##def chek_in_file_hash:



def cal_hash(file_content):
    # 确保输入是字节类型
    if not isinstance(file_content, bytes):
        raise TypeError("输入必须是字节类型")
    # 创建 SHA-256 对象
    sha256_hash = hashlib.sha256()
    # 用数据更新哈希对象
    sha256_hash.update(file_content)
    # 计算并返回哈希值
    return int(sha256_hash.hexdigest(),16)
def bsw(file_path,w=1024,d=100,r=50,max_t=1800):
    right =w
    left =0
    chunk_points=list()
    with open(file_path ,'rb') as file :
        data=file.read()
        while right<=len(data):
            w_data=data[right-w:right]
            w_hash=cal_hash(w_data )
            if right -left ==max_t :
                chunk_points .append(right )
                left=right
                right=right+w
            if w_hash%d==r:
                chunk_points .append(right)
                left=right
                right=left+w
            else :

                right+=1
        if len(data) not in chunk_points :
            chunk_points .append(len(data))
        return chunk_points
# def chunk(file_path,w,r,d):
#     chunk_points=bsw(w,r,d,file_path)
#     with open(file_path ,'rb')as f:
#         cnt=0
#         start=0
#         data=f.read()
#         for i,v in enumerate (chunk_points ):
#             new_file_path=f'new_file{cnt}.bin'
#             cnt+=1
#             chunk=data[start:v]
#             start=v
#             with open (new_file_path ,'wb') as nf:
#                 nf.write(chunk)
#
#         if start<len(data):
#             new_file_path = f'new_file{cnt}.bin'
#             cnt += 1
#             with open (new_file_path ,'wb') as nf:
#                 nf.write(chunk)

def main():

    pass


    if __name__ == "__main__":
        main()